<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Member extends Admin_Controller {
	
	function __construct()
	{
		parent::__construct();
		$this->load->model(array("Users_model"));
	}

	function index($page_no=1){
		
		$page_no = max(intval($page_no),1);
		$where_arr = array();
		$orderby = $keyword= "";
		if (isset($_GET['dosubmit'])) {
			$keyword =isset($_GET['keyword'])?safe_replace(trim($_GET['keyword'])):'';
			if($keyword!="") $where_arr[] = "concat(nickName,city,province) like '%{$keyword}%'";
			 
		}
		$where = implode(" and ",$where_arr);
		$data_list = $this->Users_model->listinfo($where,'*',$orderby , $page_no, $this->Users_model->page_size,'',$this->Users_model->page_size,page_list_url('adminpanel/member/index',true));
		
		$this->view('index',array('data_list'=>$data_list,'pages'=>$this->Users_model->pages,'keyword'=>$keyword,'require_js'=>true));
	}
	function edit($id=0){
		$id = intval($id);
		
		$data_info =$this->Users_model->get_one(array('id'=>$id));
		
		//如果是AJAX请求
		if($this->input->is_ajax_request())
		{
			if(!$data_info)exit(json_encode(array('status'=>false,'tips'=>'信息不存在')));
				$point = trim($_POST['point']);
				$integral = trim($_POST['integral']);
				$status = $this->Users_model->update(
						array(
								'integral'=>$integral,
								'point'=>$point,
						),array('id'=>$id));
				if($status)
				{
					exit(json_encode(array('status'=>true,'tips'=>'修改成功')));
				}else
				{
					exit(json_encode(array('status'=>false,'tips'=>'修改失败')));
				}
		}else
		{
			if(!$data_info)$this->showmessage('信息不存在');
			$this->view('edit',array('is_edit'=>true,'data_info'=>$data_info,'require_js'=>true));
		}
	}
}